﻿using LMM_Editor.Classes.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LMM_Editor.Classes.CustomControls
{
    /// <span class="code-SummaryComment"><summary></span>
    ///   Represents a Bordered label.
    /// <span class="code-SummaryComment"></summary></span>
    public class CustomLabel : Label
    {
        private float borderSize;
        private Color borderColor;

        private PointF point;
        private SizeF drawSize;
        private Pen drawPen;
        private GraphicsPath drawPath;
        private SolidBrush forecolorBrush;
        private IEntity entity;


        // Constructor
        //-----------------------------------------------------

        #region Constructor
        public CustomLabel()
        {
            this.borderSize = 1f;
            this.borderColor = Color.White;
            this.drawPath = new GraphicsPath();
            this.drawPen = new Pen(new SolidBrush(this.borderColor), borderSize);
            this.forecolorBrush = new SolidBrush(this.ForeColor);

            this.Invalidate();

        }
        #endregion

        // Public Properties
        //-----------------------------------------------------

        #region Public Properties
        /// <span class="code-SummaryComment"><summary></span>
        ///   The border's thickness
        /// <span class="code-SummaryComment"></summary></span>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("The border's thickness")]
        [DefaultValue(1f)]
        public float BorderSize
        {
            get { return this.borderSize; }
            set
            {
                this.borderSize = value;
                if (value == 0)
                {
                    //If border size equals zero, disable the
                    // border by setting it as transparent
                    this.drawPen.Color = Color.Transparent;
                }
                else
                {
                    this.drawPen.Color = this.BorderColor;
                    this.drawPen.Width = value;
                }

                this.OnTextChanged(EventArgs.Empty);
            }
        }

        /// <span class="code-SummaryComment"><summary></span>
        ///   The border's thickness
        /// <span class="code-SummaryComment"></summary></span>
        /// 

        
        /// <span class="code-SummaryComment"><summary></span>
        ///   The border color of this component
        /// <span class="code-SummaryComment"></summary></span>
        [Browsable(true)]
        [Category("Appearance")]
        [DefaultValue(typeof(Color), "White")]
        [Description("The border color of this component")]
        public Color BorderColor
        {
            get { return this.borderColor; }
            set
            {
                this.borderColor = value;

                if (this.BorderSize != 0)
                    this.drawPen.Color = value;

                this.Invalidate();
            }
        }

        /// <span class="code-SummaryComment"><summary></span>
        ///   The border color of this component
        /// <span class="code-SummaryComment"></summary></span>
        [Browsable(true)]
        [Category("Appearance")]
        [DefaultValue(typeof(String), "Label")]
        [Description("The name of this component")]
        public String Name
        {
            get { return this.Text; }
            set
            {
                this.Text = value;
                this.Invalidate();
            }
        }
        #endregion

        // Event Handling
        //-----------------------------------------------------

        #region Event Handling
        protected override void OnFontChanged(EventArgs e)
        {
            base.OnFontChanged(e);
            this.Invalidate();
        }

        protected override void OnTextAlignChanged(EventArgs e)
        {
            base.OnTextAlignChanged(e);
            this.Invalidate();
        }

        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
        }

        protected override void OnForeColorChanged(EventArgs e)
        {
            this.forecolorBrush.Color = base.ForeColor;
            base.OnForeColorChanged(e);
            this.Invalidate();
        }
        #endregion

    }
}